Component({
	properties: {
		matches: {
			type: Array,
			value: []
		}
	},
	data: {
		selected: {},  // 当前选中筛选项
		subSelected: {},  // 当前二级菜单选中筛选项
		currentMenu: {},  // 当前选择的下拉菜单
		currentSelect: {}, // 当前选中所有集合
		menuTitle: {},  // 当前筛选项显示
		menuState: false,  // 菜单状态默认收起
		subMenuState: false,  // 二级菜单默认收起
		currentSubmenu: false,  // 当前选中二级菜状态
		more: {},  // 更多选择中的选项
		//currentSubmenuid: {},
		animationData: {}
	},
	ready() {
		let animation = wx.createAnimation({
			duration: 500,
			timingFunction: "ease"
		})
		this.animation = animation
		animation.height('auto').step()
		this.setData({
			animationData: animation.export()
		})
	},
	methods: {
		menuDown(event) {  // 展示下拉框
			this.setData({
				currentMenu: event.currentTarget.dataset.type || this.data.currentMenu,  // 菜单类型
				menuState: true
			})
			this.triggerEvent('menuDown', this.data.currentMenu)
		},
		menuClose(){
			this.setData({
				menuState: false,
			})
		},
		current(e){  // 获取当前筛选项
			
			let typeid = e.currentTarget.dataset.typeid; // 筛选类型
			let val = e.currentTarget.dataset.val;
			let length = e.currentTarget.dataset.length || 0;  // 是否有二级菜单
			let selected = this.data.selected;
			let menuTitle = this.data.menuTitle;
			
			if (val == '报考类型' || val == '班型') {
				return false
			}
			selected[this.data.currentMenu] = typeid;
			menuTitle[this.data.currentMenu] = val
			if (length > 0){
				this.setData({
					subMenuState: true,
					menuTitle,
					selected
				})
				console.log(this.data.selected)
				return false
			}
			this.setData({
				menuState: false,
				menuTitle,
				selected
			})
			console.log(this.data.selected)
			this.triggerEvent('current', this.data.selected)
		},
		currentSub(e) {	
			console.log(e)
			let typeid = String(e.currentTarget.dataset.typeid); // 筛选类型
			let val = e.currentTarget.dataset.val;
			let subSelected = this.data.subSelected;
			let selected = this.data.selected
			let menuTitle = this.data.menuTitle;
			
			if (this.data.currentMenu == "corse16" || this.data.currentMenu == "corse17" || this.data.currentMenu == "corse18") {
				let more = this.data.more
				more[this.data.currentMenu] = typeid;
				this.setData({
					currentSubmenu: true,
					//currentSubmenuid: this.data.currentMenu,
					menuTitle,
					//selected: { ...selected, ...subSelected },
					//subSelected,
					more
				})
				console.log(this.data.more)
				return false
			}
			subSelected[this.data.currentMenu] = typeid;
			menuTitle[this.data.currentMenu] = val
			this.setData({
				menuState: false,
				currentSubmenu: true,
				menuTitle,
				selected: { ...selected, ...subSelected},
				subSelected
			})
			this.triggerEvent('current', this.data.selected)
		},
		onComplete(e){
			let selected = this.data.selected;
			let subSelected = this.data.subSelected;
			let more = this.data.more;
			
			this.setData({
				menuState: false,
				currentSubmenu: true,
				selected: { ...selected, ...subSelected, ...more}	
			})
			this.triggerEvent('current', this.data.selected)
		}
	}
})
